//index.js
//获取应用实例
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
var qqmapsdk;

var app = getApp();
console.log(app.getStorage("login_code"));
Page({
  data: {
    latitude: '',
    longitude: '',
    shopList: []
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    // 实例化API核心类
    qqmapsdk = new QQMapWX({
      key: 'LJUBZ-KP3W6-HLISX-EURTF-MQHAF-FJBFP'
    });
    var that = this
    //调用应用实例的方法获取全局数据
    // app.getUserInfo(function (userInfo) {
    //   //更新数据
    //   that.setData({
    //     userInfo: userInfo
    //   })
    // }),
    wx.getLocation({
      success: function (res) {
        that.setData({
          latitude: res.latitude,
          longitude: res.longitude
        })
        // 调用接口
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          success: function (res1) {
            that.setData({
              areaSelectedStr: res1.result.address
            })
          },
          fail: function (res) {
            console.log(res);
          },
          complete: function (res) {
            console.log(res);
          }
        });
      }
    })
  },
  search_bg_tap: function () {
    wx.redirectTo({
      url: '../search/search'
    })
  }, shop_item_Tap: function (event) {
    wx.navigateTo({
      url: '../info/info'
    })
  }, map_oper_Tap: function () {
    wx.openLocation({
      latitude: this.data.latitude,
      longitude: this.data.longitude,
      name: '我的位置',
      address: this.data.areaSelectedStr,
      scale: 15
    })
  }
})

